#include <modules\audio\fmod\fmod_audio_interface.h>

namespace DelGE
{
	namespace Modules
	{
		namespace Audio
		{
			FModAudioInterface::FModAudioInterface()
			{
				this->sName = "fmod audio interface";

				this->pSystemHandle = NULL;

				FMOD::System_Create(&this->pSystemHandle);
				if (this->pSystemHandle->init(200, FMOD_INIT_NORMAL, 0) != FMOD_OK)
					throw DelGEError("Could not init sound system!");
			}

			FModAudioInterface::~FModAudioInterface()
			{
				this->sName = "";

				this->pSystemHandle->release();

				this->pSystemHandle = NULL;
			}

			Sound* FModAudioInterface::LoadSound(string sFilepath)
			{
				return new FModSound(sFilepath, this->pSystemHandle);
			}

			Music* FModAudioInterface::LoadMusic(string sFilepath)
			{
				return new FModMusic(sFilepath, this->pSystemHandle);
			}

			void FModAudioInterface::UnloadSound(Sound* pAudioSound)
			{
				delete ((FModSound*)pAudioSound);
			}

			void FModAudioInterface::UnloadMusic(Music* pAudioMusic)
			{
				delete ((FModMusic*)pAudioMusic);
			}

			void FModAudioInterface::Update()
			{
				this->pSystemHandle->update();
			}
		}
	}
}